package com.study.leetcode;

//https://leetcode-cn.com/problems/valid-palindrome/
public class Solution_125 {
    public boolean isPalindrome(String s) {
        int length = s.length();
        int right = 0;
        int left = length - 1;
        s = s.toLowerCase();
        for (; left <= right; left++, right--) {
            if (!((s.charAt(left) >= '0' && s.charAt(left) <= '9') || (s.charAt(left) >= 'a' && s.charAt(left) <= 'z'))) {
                left++;
            }
            if (!((s.charAt(right) >= '0' && s.charAt(right) <= '9') || (s.charAt(right) >= 'a' && s.charAt(right) <= 'z'))) {
                right--;
            }
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
        }
        return true;
    }
}
